package engine.network.tests;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

import engine.network.hostSide.enums.PlayerReq;
import engine.network.hostSide.enums.RoleRequest;

public class Client {
	public static void main(String[] args) {
		System.out.println("enter the host URL");
		BufferedReader in = 
			new BufferedReader(new InputStreamReader(System.in));
		try {
			String url = in.readLine();
			Socket s = new Socket(url,4462);
			PrintWriter socket_out = 
				new PrintWriter(s.getOutputStream());
			BufferedReader socket_in = 
				new BufferedReader(
						new InputStreamReader(s.getInputStream()));
			socket_out.println(RoleRequest.PLAYER.label());
			socket_out.flush();
			String answer = socket_in.readLine();
			if(!answer.equals("OK")){
				System.out.println("there is allready an other player");
				System.exit(0);
			}
			while(true){
				System.out.println("enter the new x-axis value");
				int x = Integer.parseInt(in.readLine());
				System.out.println("enter the new y-axis value");
				int y = Integer.parseInt(in.readLine());
				System.out.println("sending the new point to the host");
				socket_out.println(PlayerReq.NEW_COORD.label());
				socket_out.println(x+"\n"+y);
				socket_out.flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}
